<?php
//
// +------------------------------------------------------------------------+
// | PHP Version 5.4                                                        |
// +------------------------------------------------------------------------+
// | Copyright (c) All rights reserved.                                     |
// +------------------------------------------------------------------------+
// | 世纪车来车往(北京）网络科技有限公司 版权所有！                                  |
// | TEL:010-63732365  HOTLINE:400-6688-365  EMAIL:clcw@clcw.com.cn         |
// | $Revision: 1.0 $                                                     |
// +------------------------------------------------------------------------+
// | Author: anguolei@clcw.com.cn                                           |
// +------------------------------------------------------------------------+
//

namespace AuctionCore\CarDealer;

/**
 * 车商拍到的车列表
 * @author  Gray Ian
 */
class MyAuctioned
{

    /**
     * 车商id
     * @var int
     */
    private $dealer_id;
    
    /**
     * 构造
     * @param    int $dealer_id  车商id
     * @return   void
     */
    public function __construct($dealer_id)
    {
        $this->dealer_id = $dealer_id;
    }
    
    /**
     * 添加车商买到的车记录
     * @param array $info
     * @return \Think\mixed
     */
    public function add($info) 
    {
        if(empty($info['dealer_id'])){
            $info['dealer_id'] = $this->dealer_id;
        }
        $info['createtime'] = date('Y-m-d H:i:s');
        return M('dealer_auctioned')->add($info);
    }


    /**
     * 修改卖的车记录
     * @param $map
     * @param $data
     * @return mixed
     */
    public function save($map, $data)
    {
        if(empty($map['dealer_id'])){
            $map['dealer_id'] = $this->dealer_id;
        }
        return M('dealer_auctioned')->where($map)->$data();
    }

    /**
     * 通过order_id获取记录
     * @param $order_id
     * @return mixed
     */
    public function get_by_order_id($order_id)
    {
        $map = array(
            'dealer_id' => $this->dealer_id,
            'order_id' => $order_id
        );
        return M('dealer_auctioned')->where($map)->find();
    }

    /**
     * 通过order_id获取记录
     * @param $order_id
     * @return mixed
     */
    public static function detail_by_order_id($order_id)
    {
        $map = array(
            'status' => 0,
            'order_id' => $order_id
        );
        $res = M('dealer_auctioned')->where($map)->find();
        return $res;
    }

    /**
     * 通过拍单id更新车商买到的车记录
     * @param integer $order_id
     * @param array $data
     * @return bool
     */
    public function up_by_order_id($order_id,$data){
        if($order_id<1){
            return false;
        }
        $map = ['dealer_id'=>$this->dealer_id,'order_id'=>$order_id];
        $res = M('dealer_auctioned')->where($map)->save($data);
        return $res;
    }

}